#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDockWidget>
#include "windowdesignarea.h"
#include "widgettree.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QList<QAction *> &getContextMenuActions();
    static bool ctrlPress;

protected:
    void changeEvent(QEvent *e);
    void closeEvent(QCloseEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);

private:
    Ui::MainWindow *ui;

    bool okToContinue();

    bool loadFile(const QString &fileName);
    bool saveFile(const QString &fileName);
    void setCurrentFile(const QString &fileName);

    void updateRecentFileActions();

    QString strippedName(const QString &fullFileName);

    void readSettings();
    void writeSettings();

    void createActions();

    void createMenus();

    void createMenuBar();
    void createToolBar();

    void createWidgetListView();
    void createWidgetTreeView();
    void createWidgetAttrEditor();
    void createWindowDesignArea();

    QDockWidget *widgetAttrEditor;
    QDockWidget *widgetListView;
    QDockWidget *widgetTreeView;
    WindowDesignArea *windowDesignArea;

    QStringList recentFiles;
    enum { MaxRecentFiles = 5 };
    QString curFile;

    QMenu *fileMenu;
    QMenu *helpMenu;
    QMenu *viewMenu;

    QToolBar *fileToolBar;
    QToolBar *AlignToolBar;
    QToolBar *editToolBar;

    QAction *newAction;
    QAction *openAction;
    QAction *saveAction;
    QAction *saveAsAction;
    QAction *exitAction;
    QAction *recentFileActions[MaxRecentFiles];
    QAction *separatorAction;

    QAction *aboutAction;
    QAction *aboutQtAction;

    QAction *widgetListViewAction;
    QAction *widgetTreeViewAction;
    QAction *widgetAttrEditorAction;

    QAction *topAlignAction;
    QAction *bottomAlignAction;
    QAction *leftAlignAction;
    QAction *rightAlignAction;
    QAction *vCenterAlignAction;
    QAction *hCenterAlignAction;

    QAction *removeAction;
    QAction *copyAction;
    QAction *dupAction;
    QAction *pasteAction;

    QList<QAction *> contextMenuActions;

    WidgetTree *widgetTree;

signals:
    void topAlign();
    void bottomAlign();
    void leftAlign();
    void rightAlign();
    void vCenterAlign();
    void hCenterAlign();

    void remove();
    void copy();
    void dup();
    void paste();

private slots:
    void newFile();
    void open();
    bool save();
    bool saveAs();
    void openRecentFile();

    void about();

    void widgetTreeModified();
};

#endif // MAINWINDOW_H
